#!/bin/bash

# 部署脚本 - 根据环境切换API地址
ENVIRONMENT=${1:-production}  # 默认生产环境

echo "构建前端应用..."
npm run build

echo "根据环境配置API地址..."

case $ENVIRONMENT in
  "production")
    API_URL="http://api.anlper.cn/api"
    ;;
  "staging")
    API_URL="http://staging-api.anlper.cn/api"
    ;;
  "local")
    API_URL="http://localhost:8000/api"
    ;;
  *)
    echo "未知环境: $ENVIRONMENT"
    exit 1
    ;;
esac

echo "设置API地址为: $API_URL"

# 替换config.js中的API地址
sed -i.bak "s|window\.__API_BASE__ = '.*';|window.__API_BASE__ = '$API_URL';|g" build/config.js

echo "部署完成！"
echo "API地址已设置为: $API_URL"
echo "build目录已准备好部署到Nginx"
